using BasicScript.Component;
using Game.Main.Model;
using SimpleJSON;

namespace Game.Component
{
	public class ClickAnimChangerItem : BaseItem
	{
		public enum State
		{
			A = 0,
			B = 1
		}

		private FrameAnimation frameAnim;

		private State state;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			frameAnim = model.GetComponent<FrameAnimation>();
			if (data.state == 1)
			{
				frameAnim.GotoLastFrame();
			}
		}

		public override void PlayQuicklyClickSound()
		{
		}

		public override void QuicklyTouch(TouchEventData touchEventData)
		{
			base.QuicklyTouch(touchEventData);
			if (frameAnim != null && !frameAnim.isPlaying)
			{
				base.PlayQuicklyClickSound();
				if (state == State.A)
				{
					state = State.B;
					frameAnim.Play();
				}
				else
				{
					state = State.A;
					frameAnim.PlayReversed();
				}
			}
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["33"] = (int)state;
		}
	}
}
